import React, {FC, useEffect} from 'react'
import {Form, Row, Col, Input} from 'antd'
import styles from './index.less'
import {PageType} from '../constant'

const {TextArea} = Input

interface HealthInformationType {
	healthInformationForm: any
	pageType: string
	detailRecord?: Record<string, string>
}

const healthInformation: FC<HealthInformationType> = ({
	healthInformationForm,
	pageType,
	detailRecord,
}) => {
	const initForm = () => {
		if (pageType !== PageType.add && detailRecord) {
			const obj = {
				disease: detailRecord.disease,
				operated: detailRecord.operated,
				trauma: detailRecord.trauma,
				familyDisease: detailRecord.familyDisease,
				hereditaryDisease: detailRecord.hereditaryDisease,
			}
			healthInformationForm.setFieldsValue(obj)
		}
	}

	useEffect(() => {
		initForm()
	}, [detailRecord])

	return (
		<div className={styles.healthInformation}>
			<div className={styles.titleBox}>健康信息</div>
			<div style={{padding: '12px 0'}}>
				<Form
					layout="horizontal"
					labelCol={{flex: '140px'}}
					labelAlign="right"
					labelWrap
					autoComplete="off"
					name="CreditInformationFrom"
					form={healthInformationForm}
					disabled={pageType === PageType.detail}>
					<Row>
						<Col span={8}>
							<Form.Item
								name="disease"
								label="疾病"
								rules={[{max: 30}]}>
								<TextArea
									placeholder={
										pageType === PageType.detail
											? ''
											: '请输入'
									}
									autoSize
								/>
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="operated"
								label="手术"
								rules={[{max: 30}]}>
								<TextArea
									placeholder={
										pageType === PageType.detail
											? ''
											: '请输入'
									}
									autoSize
								/>
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="trauma"
								label="外伤"
								rules={[{max: 30}]}>
								<TextArea
									placeholder={
										pageType === PageType.detail
											? ''
											: '请输入'
									}
									autoSize
								/>
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="familyDisease"
								label="家族病史"
								rules={[{max: 30}]}>
								<TextArea
									placeholder={
										pageType === PageType.detail
											? ''
											: '请输入'
									}
									autoSize
								/>
							</Form.Item>
						</Col>
						<Col span={8}>
							<Form.Item
								name="hereditaryDisease"
								label="遗传病史"
								rules={[{max: 30}]}>
								<TextArea
									placeholder={
										pageType === PageType.detail
											? ''
											: '请输入'
									}
									autoSize
								/>
							</Form.Item>
						</Col>
					</Row>
				</Form>
			</div>
		</div>
	)
}

export default healthInformation
